package com.ashok.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.ashok.domain.User;

@Repository(value = "userDao")
public class UserDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public User getUser(String username, String password) {
		String query = "select username,password from users where username=? and password=?";

		List<User> users = jdbcTemplate.queryForList(query, new String[] {}, User.class);
		if(users.isEmpty()){
			System.out.println("Can't find user "+username);
			return null;
		}else{
			System.out.println("User found "+username);
			return users.get(0);
		}
	}
	
}
